<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/vue-2.4.0.js"></script>
</head>
<body>
<div id="app">
    <div>
        <span>用户名：</span>
        <span>
            <input type="text" v-model.lazy="uname">
        </span>
        <span>{{tip}}</span>
    </div>
</div>
<script>
    var vm = new Vue({
        el:'#app',
        data:{
            uname:'',
            tip:''
        },
        methods:{
            checkName(uname){
                setTimeout(()=>{
                    if (uname==='admin'){
                        this.tip='用户名已经存在，请更换一个'
                    }else {
                        this.tip='用户名可以使用'
                    }
                },2000)
            }
        },
        watch:{
            uname(val){
                this.checkName(val)
                this.tip='验证中'
            }
        }
    })
</script>
</body>
</html>
